package com.rabbiter.oes.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rabbiter.oes.entity.Teacher;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface TeacherMapper extends BaseMapper<Teacher> {

    /**
     * 某学院的老师人数
     * @param collegeId
     * @return
     */
    default Long selectCountByCollegeId(Integer collegeId) {
        return selectCount(Wrappers.lambdaQuery(Teacher.class).eq(Teacher::getCollegeId, collegeId));
    }

    IPage<Teacher> findAllByTerms(Page<Teacher> page, String name, String sex, String tel, String cardId);

    List<Teacher> findAll();

    default Long findCountByAcc (String acc) {
        LambdaQueryWrapper<Teacher> teacherWrapper = Wrappers.lambdaQuery(Teacher.class).eq(Teacher::getAcc, acc);
        return selectCount(teacherWrapper);
    }

    Teacher findById(Integer id);

    Teacher selectByAccAndPwd(String acc);


    /**
     * 根据id修改密码
     * @param id
     * @param pwd
     * @return
     */
    default int updatePwdById(Integer id, String pwd) {
        Wrapper<Teacher> updateWrapper = Wrappers.lambdaUpdate(Teacher.class).eq(Teacher::getId, id).set(Teacher::getPwd, pwd);
        return update(new Teacher(), updateWrapper);
    }

}
